<template>
  <div style="text-align: center">
   <van-nav-bar title="京东登录注册" left-arrow @click-left="onClickLeft" />

    <!-- //登陆表单 -->
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        placeholder="账户名/邮箱/手机号"
        type="username"
        name="账号"
        label="账号"
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        placeholder="请输入密码"
        name="密码"
        label="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button
          round
          block
          type="info"
          color="linear-gradient(to right, #ff6034, #ee0a24)"
          native-type="submit"
          >登录</van-button
        >
      </div>
      <span style="float: left; margin-left: 18px">短信验证码登录</span>
      <span @click="register" style="float: right; margin-right: 18px"
        >手机快速注册</span
      >
    </van-form>
  </div>
</template>

<script>
export default {
  mounted(){
    
  },
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
        onClickLeft() {
      this.$router.push('/MyHome');
    },
    // 登录
    onSubmit(values) {
      this.$http({
        url: "api/user/login",
        method: "post",
        data: {
          loginname: this.username,
          password: this.password,
        }
      }).then(
        (res) => {
            sessionStorage.setItem("token",res.data.data.token)
            sessionStorage.setItem("userid",res.data.data.userid)
            this.$router.back()
        },
        (rej) => {
          console.log(rej);
        }
      );
    },
    //跳转注册页面
    register() {
      this.$router.push("/Register");
    },
  },
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
</style>